- [[#minibuffer][minibuffer]]
- [[#side-window][side window]]
- [[#frame][frame]]
+ - [[#custom][custom]]
- [[#custom-string-replacement][Custom String Replacement]]
- [[#key-based-replacement]["Key-Based" replacement]]
- [[#key-and-description-replacement][Key and Description replacement]]
There are more options than the ones described here. All of the configurable
variables are available through =M-x customize-group which-key=.
** Several Popup Types
-There are three different popup types that which-key can use to display the
-available keys. The variable =which-key-popup-type= decides which one is used.
+There are three different popup types that which-key can use by default to
+display the available keys. The variable =which-key-popup-type= decides which
+one is used.
*** minibuffer
#+BEGIN_SRC emacs-lisp
(setq which-key-popup-type 'minibuffer)
(setq which-key-side-window-max-height 0.25)
#+END_SRC
*** frame
+
#+BEGIN_SRC emacs-lisp
(setq which-key-popup-type 'frame)
#+END_SRC
;; max height of which-key frame: number of lines (an integer)
(setq which-key-frame-max-height 20)
#+END_SRC
+
+*** custom
+Write your own display functions! This requires you to write three functions,
+=which-key/custom-popup-max-dimensions-function=,
+=which-key/custom-show-popup-function=, and
+=which-key/custom-hide-popup-function=. Refer to the documentation for those
+variables for more information, but here is a working example (this is the
+current implementation of side-window bottom).
+
+
+#+BEGIN_SRC emacs-lisp
+(setq which-key-popup-type 'custom)
+(defun which-key/custom-popup-max-dimensions-function (ignore)
+ (cons
+ (which-key/height-or-percentage-to-height which-key-side-window-max-height)
+ (frame-width)))
+(defun fit-horizonatally ()
+ (let ((fit-window-to-buffer-horizontally t))
+ (fit-window-to-buffer)))
+(defun which-key/custom-show-popup-function (act-popup-dim)
+ (let* ((alist '((window-width . fit-horizontally)
+ (window-height . fit-window-to-buffer))))
+ (if (get-buffer-window which-key--buffer)
+ (display-buffer-reuse-window which-key--buffer alist)
+ (display-buffer-in-major-side-window which-key--buffer 'bottom 0 alist))))
+(defun which-key/custom-hide-popup-function ()
+ (when (buffer-live-p which-key--buffer)
+ (quit-windows-on which-key--buffer)))
+#+END_SRC
+
** Custom String Replacement
You can customize the way the keys show in the buffer using three different
replacement methods, each of which corresponds replacement alist. The basic idea
(const :tag "In first line" top)
(const :tag "Hide" nil)))
(defcustom which-key-popup-type 'minibuffer
- "Supported types are minibuffer, side-window and frame."
+ "Supported types are minibuffer, side-window, frame, and custom."
:group 'which-key
:type '(radio (const :tag "Show in minibuffer" minibuffer)
(const :tag "Show in side window" side-window)
- (const :tag "Show in popup frame" frame)))
+ (const :tag "Show in popup frame" frame)
+ (const :tag "Use your custom display functions" custom)))
(defcustom which-key-side-window-location 'right
"Location of which-key popup when `which-key-popup-type' is
side-window. Should be one of top, bottom, left or right."
"Face for special keys (SPC, TAB, RET)"
:group 'which-key)
+;; Custom popup
+(defvar which-key/custom-popup-max-dimensions-function nil
+ "Variable to hold a custom max-dimensions function.
+Will be passed the width of the active window and is expected to
+return the maximum height in lines and width in characters of the
+which-key popup in the form a cons cell (height . width).")
+(defvar which-key/custom-hide-popup-function nil
+ "Variable to hold a custom hide-popup function.
+It takes no arguments and the return value is ignored.")
+(defvar which-key/custom-show-popup-function nil
+ "Variable to hold a custom show-popup function.
+Will be passed the required dimensions in the form (height .
+width) in lines and characters respectively. The return value is
+ignored.")
+
;; Internal Vars
;; (defvar popwin:popup-buffer nil)
(defvar which-key--buffer nil
(cl-case which-key-popup-type
(minibuffer (which-key/hide-buffer-minibuffer))
(side-window (which-key/hide-buffer-side-window))
- (frame (which-key/hide-buffer-frame))))
+ (frame (which-key/hide-buffer-frame))
+ (custom (funcall #'which-key/custom-hide-popup-function))))
(defun which-key/hide-buffer-minibuffer ()
"Does nothing. Stub for consistency with other hide-buffer
(cl-case which-key-popup-type
(minibuffer (which-key/show-buffer-minibuffer act-popup-dim))
(side-window (which-key/show-buffer-side-window act-popup-dim))
- (frame (which-key/show-buffer-frame act-popup-dim)))))
+ (frame (which-key/show-buffer-frame act-popup-dim))
+ (custom (funcall #'which-key/custom-show-popup-function act-popup-dim)))))
(defun which-key/show-buffer-minibuffer (act-popup-dim)
"Does nothing. Stub for consistency with other show-buffer
(cl-case which-key-popup-type
(minibuffer (which-key/minibuffer-max-dimensions))
(side-window (which-key/side-window-max-dimensions))
- (frame (which-key/frame-max-dimensions))))
+ (frame (which-key/frame-max-dimensions))
+ (custom (funcall #'which-key/custom-popup-max-dimensions-function selected-window-width))))
(defun which-key/minibuffer-max-dimensions ()
"Return max-dimensions of minibuffer (height . width) in lines